<style>
	#logoBtn,#desImgBtn{
		width:130px;
	}
</style>
<#include "/admin/public.html">
<div class="uk-layui-form">
    <form class="layui-form uk-form" action="/admin/blockmanagement/update.html" method="post">

    	<input type="hidden" name="id" value="${blockmanagementData.id!''}">
    	
    	<input type="hidden" name="fileurl" id="fileurl" value="${blockmanagementData.fileurl!''}">
        <input type="hidden" name="filename" id="filename" value="${blockmanagementData.filename!''}">
        <input type="hidden" name="graphurl" id="graphurl" value="${blockmanagementData.graphurl!''}">
        <input type="hidden" name="graphdescription" id="graphdescription" value="${blockmanagementData.graphdescription!''}">
        <input type="hidden" id="blocknameVal" value="${blockmanagementData.blockname!''}">
        <input type="hidden" id="judge" value="${blockmanagementData.parentid!''}">
        <input type="hidden" value="${blockmanagementData.briefintroduction!''}">

        <div class="layui-form-item">
            <label class="layui-form-label">选择</label>
            <div class="layui-input-inline">
                <select name="selectCategory" id="selectCategory" placeholder="请选择" lay-filter="selectCategory">
                	<option value="" >请选择</option>
					<option value="0" <#if blockmanagementData.parentid == "">selected</#if>>板块</option>
					<option value="1" <#if blockmanagementData.parentid != "">selected</#if>>分类</option>
				</select>
            </div>
        </div>
        <div class="layui-form-item layui-hide">
            <label class="layui-form-label">板块名称</label>
            <div class="layui-input-inline">
                <input type="text" name="" id="blockname"  class="layui-input" placeholder="请输入板块名称">
            </div>
        </div>
        <div class="layui-form-item  layui-hide">
            <label class="layui-form-label">分类名称</label>
            <div class="layui-input-inline">
                <input type="text" name=""  id="classifyname" class="layui-input" placeholder="请输入分类名称">
            </div>
        </div>
        <div class="layui-form-item  layui-hide">
            <label class="layui-form-label">所属板块</label>
            <div class="layui-input-inline">
                <select name="parentid" id="parentid" placeholder="请选择">
                	<option value="">请选择</option>
                	<#if Listname?? && Listname??>
					<#list Listname as list>
						<option value="${list.id!''}" <#if blockmanagementData.parentid == list.id>selected</#if>>${list.blockname!''}</option>
					</#list>
					</#if>
				</select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">板块logo</label>
            <div class="layui-input-inline">
                <a class="layui-btn layui-btn-primary" id="logoBtn"><i class="layui-icon">&#xe608;</i>上传logo</a>
            </div>
        </div>
        <div class="layui-form-item  <#if blockmanagementData.fileurl == "">layui-hide</#if>">
		    <label class="layui-form-label"></label>
		    <div class="layui-input-inline">
		    	<img alt="" style="width:130px" id="logoImg" <#if blockmanagementData.fileurl != "">src="/res/blockmanagement/${blockmanagementData.fileurl!''}.html"</#if><#if blockmanagementData.fileurl == "">src=""</#if>>
		    </div>
	    </div>
        <div class="layui-form-item">
            <label class="layui-form-label">描述图</label>
            <div class="layui-input-inline">
                <a class="layui-btn layui-btn-primary" id="desImgBtn"><i class="layui-icon">&#xe608;</i>上传图片</a>
            </div>
        </div>
        <div class="layui-form-item <#if blockmanagementData.graphurl == "">layui-hide</#if>">
		    <label class="layui-form-label"></label>
		    <div class="layui-input-inline">
		    	<img alt="" style="width:130px" id="desImg" <#if blockmanagementData.graphurl != "">src="/res/blockmanagement/${blockmanagementData.graphurl!''}.html"</#if><#if blockmanagementData.graphurl == "">src=""</#if>>
		    </div>
	    </div>
        <div class="layui-form-item">
            <label class="layui-form-label">板块简介</label>
            <div class="layui-input-block">
                <textarea id="briefintroduction" name="briefintroduction" value="${blockmanagementData.briefintroduction!''}" required lay-verify="required" placeholder="请输入内容" class="layui-textarea fly-editor" style="height: 160px;">${blockmanagementData.briefintroduction!''}</textarea>
            </div>
        </div>
        
        <div class="layui-form-button">
            <div class="layui-button-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
<script>
	console.log("${blockmanagementData}");
    var url = "/uploadblockmanagement";
  	//触发的id
    var ids = new Array("logoBtn","desImgBtn");
    //表单验证提交
    layui.use('form', function() {
        var form = layui.form();
        
        if($("#judge").val() == ""){
        	$("#blockname").parent().parent().removeClass("layui-hide").addClass("layui-show");//板块名称
        	$("#blockname").val($("#blocknameVal").val());
        	$("#blockname").attr("name","blockname");
        }else{
        	$("#classifyname").parent().parent().removeClass("layui-hide").addClass("layui-show");//分类名称
    		$("#parentid").parent().parent().removeClass("layui-hide").addClass("layui-show");//所属板块
        	$("#classifyname").val($("#blocknameVal").val());
        	$("#classifyname").attr("name","blockname");
        }
        form.render(); //更新全部
      	//根据选择显示
        form.on('select(selectCategory)', function(data){
	      	if(data.value == "0"){//显示板块名称
	      		$("#classifyname").parent().parent().removeClass("layui-show").addClass("layui-hide");//分类名称
	    		$("#parentid").parent().parent().removeClass("layui-show").addClass("layui-hide");//所属板块
	    		$("#blockname").parent().parent().removeClass("layui-hide").addClass("layui-show");//板块名称
	    		$("#blockname").attr("name","blockname");
	    		$("#classifyname").attr("name","");
	      	}else{
	      		$("#classifyname").parent().parent().removeClass("layui-hide").addClass("layui-show");//分类名称
	    		$("#parentid").parent().parent().removeClass("layui-hide").addClass("layui-show");//所属板块
	    		$("#blockname").parent().parent().removeClass("layui-show").addClass("layui-hide");//板块名称
	    		$("#classifyname").attr("name","blockname");
	    		$("#blockname").attr("name","");
	      	}
    	}); 
    });
    
    $.each(ids,function(i,n){
    	var self = this.toString();
    	//实例化一个plupload上传对象
        var uploader = new plupload.Uploader({
        	browse_button:self, //触发文件选择对话框的按钮，为那个元素id
            url: "${base}" + url, //服务器端的上传页面地址
            flash_swf_url: '${ctxStatic}/plupload/js//Moxie.swf', //swf文件，当需要使用swf方式进行上传时需要配置该参数
            silverlight_xap_url: '${ctxStatic}/plupload/js/Moxie.xap', //silverlight文件，当需要使用silverlight方式进行上传时需要配置该参数
            filters: {
                mime_types: [{
                        title: "Image files",
                        extensions: "jpg,jpeg,png,gif"
                    },

                ],
                max_file_size: '40mb',
            },
        });
        //在实例对象上调用init()方法进行初始化
        uploader.init();
      	//绑定各种事件，并在事件监听函数中做你想做的事
        uploader.bind('FilesAdded',function(uploader,files){
        	if(uploader.settings.browse_button[0].id == "logoBtn"){
				$("#logoImg").parent().parent().removeClass("layui-hide");
				$("#logoImg").attr("src","/images/loading-slide.gif");
        	}else if(uploader.settings.browse_button[0].id == "desImgBtn"){
        		$("#desImg").parent().parent().removeClass("layui-hide");
				$("#desImg").attr("src","/images/loading-slide.gif");
        	}
            uploader.start()
        });
      	//上传后回调
        uploader.bind('FileUploaded', function(uploader, UploadProgress, responseObject) {
            var obj = $.parseJSON(responseObject.response);
			picurl = {"fileName": obj.fileName,"filePath": obj.filePath,"fileId": obj.fileId};
			if(uploader.settings.browse_button[0].id == "logoBtn"){
				$("#logoImg").attr("src","/res/blockmanagement/" + obj.fileId +".html");
				$("#fileurl").val(obj.fileId);
				$("#filename").val(obj.fileName.split(".")[0]);
        	}else if(uploader.settings.browse_button[0].id == "desImgBtn"){
        		$("#desImg").attr("src","/res/blockmanagement/" + obj.fileId +".html");
        		$("#graphurl").val(obj.fileId);
        		$("#graphdescription").val(obj.fileName.split(".")[0]);
        	}
        });
      	//报错
        uploader.bind('Error', function(up, err) {
            if (err.code == '-600') {
            	layer.msg('文件最多可上传40M', {icon: 5});
            }

        });
    });
</script>